<?php
//开启session
session_start();
//包含数据库配置文件
include '../public/dbconfig.php';
//包含函数库文件
include '../public/functions.php';
//调用函数 链接数据库
$link = con();

//接收用户登录信息
//接收用户名
$username = $_POST['username'];
//接收密码
$password = md5($_POST['pwd']);

//准备sql
$sql = "select id,username,password,qx from user where username='{$username}'";

//执行sql
$res = mysqli_query($link, $sql);
//判断执行结果
if($res && mysqli_num_rows($res)){
	$uinfo = mysqli_fetch_assoc($res);
	//用户名正确 继续判断密码
	if($uinfo['password'] == $password){
		$_SESSION['username'] = $username;
		$_SESSION['id'] = $uinfo['id'];
		$_SESSION['qx'] = $uinfo['qx'];
		echo '<script>alert("恭喜您!登录成功,将为您跳转到首页");window.location.href="index.php";</script>';
	}else{
		//密码错误
		echo '<script>alert("密码错误");window.location.href="index.php";</script>';
	}
}else{
	//用户名错误
	echo '<script>alert("用户名错误");window.location.href="index.php";</script>';
}
